package com.demo.controller;

import java.util.List;
import java.util.UUID;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.demo.bean.WdPurpose;
import com.demo.bean.WdChangeType;
import com.demo.service.PurposeService;


@Controller
public class PurposeController {

	@Autowired
	private PurposeService service;

	@RequestMapping("/purpose.do")
	public String getList(HttpServletRequest requset,WdPurpose bean) {
		List<WdPurpose> list = service.getList(bean);
		requset.setAttribute("list", list);
		return "purpose";
	}

	@RequestMapping("/purpose_to_add.do")
	public String purposeToAdd() {
		return "purpose_add";
	}

	@RequestMapping("/purpose_add.do")
	public String purposeAdd(WdPurpose bean) {
		bean.setPurposeId(UUID.randomUUID().toString().replace("-", ""));
		service.insertSelective(bean);
		return "redirect:purpose.do";
	}

	@RequestMapping("/deletePurpose.do")
	public String purposeDelete(String purposeId) {
		service.deleteSelective(purposeId);
		return "redirect:purpose.do";
	}

	@RequestMapping("/toupdatePurpose.do")
	public String purposeToUpdate(HttpServletRequest requset,
			String purposeId) {
		WdPurpose bean = service.getById(purposeId);
		requset.setAttribute("bean", bean);
		return "purpose_update";
	}

	@RequestMapping("/updatePurpose.do")
	public String purposeUpdate(WdPurpose bean) {
		service.updatePurpose(bean);
		return "redirect:purpose.do";
	}

	
}
